﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;

namespace EmotionRecognitionEntities
{
   public  class Picture
    {

       int pictureID;
       //
       string path;

       List<int> auList=new List<int>();

       Image pictureImage;

       int chunkId;

       int isChecked;

       public Picture(int pictureID,string Path, int chunkId, int isChecked)
       {
           this.pictureID = pictureID;
           
           this.path = Path;
           this.pictureImage = new Bitmap(path);
           this.chunkId = chunkId;
           this.isChecked = isChecked;
          
       }

       public void  LoadPictureFromDiffrentPath(string path)
       {
           this.path = path;
           pictureImage = new Bitmap(path);

       }


       public void LoadAUsFromXML(List<int> list)
       {
           string xmlpath = new string(path.ToArray());
           string newxmlpath= xmlpath.Replace(".jpg", ".xml");
           XmlDocument xmldoc = new XmlDocument();
           xmldoc.Load(newxmlpath);

           foreach (XmlNode node in xmldoc.SelectNodes("ActionUnitCoding/ActionUnit"))
           {
               string a = node.Attributes[0].InnerText;

               try
               {
                   int au = Convert.ToInt32(a);
                   //Check if AU from XML is match to AU's in DB
                   if (list.Contains(au))
                       auList.Add(Convert.ToInt32(a));
               }
               // if convert is not successeded - dont add this AU to AUList
               catch (Exception)
               {
                   break;
               }
           }
           
       }


       #region public properties

       public int PictureID
       {
           get
           {
               return pictureID;
           }

           set
           {
               pictureID = value;
           }
       }

       public string Path
       {
           get
           {
               return path;
           }

           set
           {
               path = value;
           }
       }

       public List<int> AUList
       {
           get
           {
               return auList; 
           }

           set
           {
               auList = value;
           }
       }

       public Image PictureImage
       {
           get
           {
               return pictureImage; ;
           }

           set
           {
               pictureImage = value;
           }
       }

       public int ChunkID
       {
           get
           {
               return chunkId; 
           }

           set
           {
               chunkId = value;
           }
       }


       public int IsChecked
       {
           get
           {
               return isChecked; 
           }

           set
           {
               isChecked = value;
           }
       }


       #endregion



    }
}
